define(function(require) {

	require("component/js/jquery-2.1.4.min.js");
	require("component/js/jquery-form.js");
	
	jQuery('div.error').hide();
	
	$("body").on("click",function(){
		judgeInputStatus();
	});
	
	$("#loginName").blur(function(){
		judgeInputStatus();
	});
	$("#password").blur(function(){
		judgeInputStatus();
	});
	$("#loginBtn").click(function(){
        $("#loginForm").ajaxSubmit({
           success: function(result){
        	   var response = $.parseJSON(result);
           	   if(response.result=="SUCCESS"){
            	   window.location.href="http://localhost:8080/erhuogou/manager/userList.html";
            	   sessionStorage.setItem("admin",response.data);
               }else {
            	   $("#nameandpassworderror").show();
               }
           }
        });
    });
	
	$("#loginName").focus();
	$("#loginForm").keydown(function(e){
		 var e = e || event,
		 keycode = e.which || e.keyCode;
		 if (keycode==13) {
		  $("#loginBtn").trigger("click");
		 }
	});
	
	$("#verCodePic").click(function(){
    	getrCode();
    });
    
	function getrCode(){
		var d = Math.round(Math.random()*9+1);;
		var s = "manager/images/code/code"+d+".jpg";
		$("#verCodePic").find("img").attr("src",s);
	}
	
	 function judgeInputStatus(){
		 if($("#password").val()==""){
			 if($("#loginName").val()==""){
				$("#nameerror").css("display","block");
				$("#passworderror").css("display","none");
				$(".errorG").css("display","none");
				$("#loginBtn").attr("disabled",true);
			 }else{
				$("#nameerror").css("display","none");
				$("#passworderror").css("display","block");
				$(".errorG").css("display","none");
				$("#loginBtn").attr("disabled",true);
			 }
		 }else{
			 if($("#loginName").val()==""){
				$("#nameerror").css("display","block");
				$("#passworderror").css("display","none");
				$(".errorG").css("display","none");
				$("#loginBtn").attr("disabled",true);
			 }else{
				$("#nameerror").css("display","none");
				$("#passworderror").css("display","none");
				$(".errorG").css("display","none");
				$("#loginBtn").attr("disabled",false);
			 }
		 }
	 }
});